package com.generalbackend.common.dingtalk.entity;

import lombok.Data;

/**
 * @author tim.xie
 * @date 2021/12/24 16:56
 */
@Data
public class DingRequestBody {
    private DingRequestBody() {}
    /**
     * 消息类型
     */
    private String msgtype;
    /**
     * at信息
     */
    private At at;
    /**
     * link类型
     */
    private Link link;
    /**
     * text类型
     */
    private String text;
    /**
     * markdown类型
     */
    private Markdown markdown;
    /**
     * actionCard类型
     */
    private ActionCard actionCard;
    /**
     * FeedCard类型
     */
    private FeedCard feedCard;

    /**
     * 构建link类型的请求体
     * @param link
     * @return
     */
    public static DingRequestBody buildLink(Link link) {
        DingRequestBody linkRequest = new DingRequestBody();
        linkRequest.setLink(link);
        linkRequest.setMsgtype("link");
        return linkRequest;
    }

    /**
     * 构建text类型的请求体
     * @param text
     * @return
     */
    public static DingRequestBody buildText(String text) {
        DingRequestBody textRequest = new DingRequestBody();
        textRequest.setText(text);
        textRequest.setMsgtype("text");
        return textRequest;
    }

    /**
     * 构建markdown类型的请求体
     * @param markdown
     * @return
     */
    public static DingRequestBody buildMarkDown(Markdown markdown) {
        DingRequestBody markdownRequest = new DingRequestBody();
        markdownRequest.setMarkdown(markdown);
        markdownRequest.setMsgtype("markdown");
        return markdownRequest;
    }

    /**
     * 构建actionCard类型请求体
     * @param actionCard
     * @return
     */
    public static DingRequestBody buildActionCard(ActionCard actionCard) {
        DingRequestBody actionCardRequest = new DingRequestBody();
        actionCardRequest.setActionCard(actionCard);
        actionCardRequest.setMsgtype("actionCard");
        return actionCardRequest;
    }

    /**
     * 构建feedCard类型请求体
     * @param feedCard
     * @return
     */
    public static DingRequestBody buildFeedCard(FeedCard feedCard) {
        DingRequestBody feedCardRequest = new DingRequestBody();
        feedCardRequest.setFeedCard(feedCard);
        feedCardRequest.setMsgtype("feedCard");
        return feedCardRequest;
    }

    public DingRequestBody at(At at) {
        this.at = at;
        return this;
    }
}
